<?php
    /**
    * This is the component SMailer
    * Integrate with Swift Mailer library
    * I make mailing easily
    */
    Yii::import('application.vendors.SMailer.classes.Swift', true);
    Yii::registerAutoloader(array('Swift','autoload'));
    Yii::import('application.vendors.SMailer.swift_init', true);

    class SMailer extends CApplicationComponent
    {
        public $host;
        public $username;
        public $password;
        public $port;
        public $secure;
        public function init()
        {
            parent::init();
            //echo "This is component mailer!";
        }
        public function sendMail( $to, $subject, $body)
        {
            $message = Swift_Message::newInstance()
            ->setSubject($subject)
            ->setFrom($to)
            ->setTo($this->username)
            ->setBody($body, 'text/html');

            $transport = Swift_SmtpTransport::newInstance($this->host, $this->port,$this->secure)
            ->setUsername($this->username)
            ->setPassword($this->password);

            $mailer = Swift_Mailer::newInstance($transport);
            $mailer->send($message);
        }

    }
?>
